package com.whstudio.util.mvc.data.sql;

import java.util.ArrayList;
import java.util.List;

import com.whstudio.util.mvc.dao.AbstractDAO;

public abstract class ASql extends AbstractDAO implements ISql{
	protected List<Arg> args=new ArrayList<Arg>();
	protected List<String> tables=new ArrayList<String>();
	protected ISql subSql=null;
	protected List<String> columns=new ArrayList<String>();
	protected String sql=null;
	
	public ISql setSubSql(ISql e){
		this.subSql=e;
		return this;
	}
	
	public ISql addColumn(String e){
		if(e==null){
			e="";
		}
		columns.add(e.toUpperCase());
		return this;
	}
	
	public ISql addTable(String e){
		if(e==null){
			e="";
		}
		tables.add(e.toUpperCase());
		return this;
	}
	
	public ISql addArg(Arg e){
		args.add(e);
		return this;
	}
	
	public ISql addArgs(Arg[] e){
		if(e==null){
			return this;
		}
		int len=e.length;
		for(int i=0;i<len;i++){
			addArg(e[i]);
		}
		return this;
	}
	
	public ISql setArgs(List<Arg> e){
		args=e;
		return this;
	}
	
	public List<Arg> getArgs(){
		return args;
	}
	
	public String toString(){
		if(sql==null){
			try {
				build();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return sql;
	}
	
	@Override
	public ISql setEnds(String ends) {
		
		return null;
	}
	
	@Override
	public void setSql(String sqlString){
		this.sql=sqlString;
	}

}
